package org.zjh.model;

import org.zjh.controller.GameController;
import org.zjh.utils.PokerUtil;
import org.zjh.utils.RandomUtil;
import org.zjh.view.game.GamePanel;
import org.zjh.view.ui.GameUi;

import javax.swing.*;

/**
 * @description: 电脑玩家类
 * @author 郑佳豪
 * @date 2024/10/10 15:42
 * @version 1.0
 */
public abstract class ComputerPlayer extends Player {


    public ComputerPlayer() {

    }


    public ComputerPlayer(String nickname, int score) {
        super(nickname, score);
    }


    @Override
    public void callPoint(Player callPointCurrentPlayer) {
        //获取游戏面板
        GamePanel gamePanel = GameUi.gameFrame.getGamePanel();
        //当前叫分玩家标签
        JLabel curPlayerCallPointResultLabel;


        if (callPointCurrentPlayer instanceof ComputerA) {
            //如果是电脑A类型 当前叫分结果标签 就是 电脑玩家A类型的叫分结果标签
            curPlayerCallPointResultLabel = gamePanel.getComputerAPlayerCallPointResultJLabel();
        } else {
            //如果是电脑B类型 当前叫分结果标签 就是 电脑玩家B类型的叫分结果标签
            curPlayerCallPointResultLabel = gamePanel.getComputerBPlayerCallPointResultJLabel();
        }


        //叫分数组
        int[] points = {0, 3, 2, 1};
        //获取倍数值
        int multiple = Integer.parseInt(gamePanel.getMultipleJLabel().getText().substring(3));
        //用数组的长度 减去 倍数 获得可以叫分范围 然后再这个范围里面随机选
        int callPoint = points[RandomUtil.RANDOM.nextInt(points.length - multiple)];

        if (callPoint == 0) {
            curPlayerCallPointResultLabel.setText("不叫");
        } else {
            //将倍数更新
            gamePanel.getMultipleJLabel().setText("倍数：" + callPoint);
            curPlayerCallPointResultLabel.setText(callPoint + "分");
        }
        callPointCurrentPlayer.setCallPointResult(callPoint);


    }


    @Override
    public void discardPoker() {
        PokerUtil.autoDiscardPoker(this,GameController.getInstance().getNowDeskPokerList());
    }


}
